package com.nuanshui.heatedloan.task.proxy;

import java.util.HashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.nuanshui.heatedloan.task.constant.BeanClassFactoryType;
import com.nuanshui.heatedloan.task.exeception.BeanClassFactoryNotSupportException;

/**
 * 消息监听工厂类的构造器
 * @param 
 * @author guohao
 * @date 2017年2月13日 上午9:54:08
 * @since $
 */
public class MessageListenerBeanFactoryBuilder {

	private Logger logger = LoggerFactory.getLogger(MessageListenerBeanClassFactory.class);
	
	private static final String DEFAULT_FACTORY = BeanClassFactoryType.JAVASSIST;
	
	private static  HashMap<String,MessageListenerBeanClassFactory> factorys = new HashMap<>();
	/**
	 * 动态构造一个监听器工厂类
	 * @param @param type  动态生成代码的类型（比如javassist）
	 * @param @return
	 * @author guohao
	 * @date 2017年2月13日 上午9:54:33
	 * @since $
	 */
	public static MessageListenerBeanClassFactory build(String type) {
		MessageListenerBeanClassFactory classFactory =  factorys.get(type);
		if(classFactory !=null) return classFactory;
		if(BeanClassFactoryType.JAVASSIST.equals(type)) {
			classFactory =  new JavassistMessageListenerBeanClassFactory();
			factorys.put(type, classFactory);
			return classFactory;
		}else {
			throw new BeanClassFactoryNotSupportException(type+ " 暂不支持");
		}	
	}
	
	
	public static MessageListenerBeanClassFactory build() {
           return build(DEFAULT_FACTORY);
	}
	
}
